home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1092
/
1092.xpi
/
chrome
/
dotcomplete.jar
/
content
/
dotcomplete
/
dotcomplete.js
< prev
next >
Wrap
Text File
|
2006-11-10
|
13KB
|
270 lines
var dotCOMplete =
{
TLDList: [
// All active country code- and generic- top level domains.
// Taken from http://data.iana.org/TLD/tlds-alpha-by-domain.txt
// Version 2006101901, Last Updated Fri Oct 20 08:07:01 2006 UTC
"ac","ad","ae","aero","af","ag","ai","al","am","an","ao","aq","ar","arpa","as","at",
"au","aw","ax","az","ba","bb","bd","be","bf","bg","bh","bi","biz","bj","bm","bn",
"bo","br","bs","bt","bv","bw","by","bz","ca","cat","cc","cd","cf","cg","ch","ci",
"ck","cl","cm","cn","co","com","coop","cr","cu","cv","cx","cy","cz","de","dj","dk",
"dm","do","dz","ec","edu","ee","eg","er","es","et","eu","fi","fj","fk","fm","fo",
"fr","ga","gb","gd","ge","gf","gg","gh","gi","gl","gm","gn","gov","gp","gq","gr",
"gs","gt","gu","gw","gy","hk","hm","hn","hr","ht","hu","id","ie","il","im","in",
"info","int","io","iq","ir","is","it","je","jm","jo","jobs","jp","ke","kg","kh",
"ki","km","kn","kr","kw","ky","kz","la","lb","lc","li","lk","lr","ls","lt","lu",
"lv","ly","ma","mc","md","mg","mh","mil","mk","ml","mm","mn","mo","mobi","mp","mq",
"mr","ms","mt","mu","museum","mv","mw","mx","my","mz","na","name","nc","ne","net",
"nf","ng","ni","nl","no","np","nr","nu","nz","om","org","pa","pe","pf","pg","ph",
"pk","pl","pm","pn","pr","pro","ps","pt","pw","py","qa","re","ro","ru","rw","sa",
"sb","sc","sd","se","sg","sh","si","sj","sk","sl","sm","sn","so","sr","st","su",
"sv","sy","sz","tc","td","tf","tg","th","tj","tk","tl","tm","tn","to","tp","tr",
"travel","tt","tv","tw","tz","ua","ug","uk","um","us","uy","uz","va","vc","ve","vg",
"vi","vn","vu","wf","ws","ye","yt","yu","za","zm","zw"
],
preferences: Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService).getBranch("dotCOMplete."),
compatTBPrefs: false,
initDotCOMplete: function()
{
setTimeout(window.dotCOMplete.delayedInitDotCOMplete,1);
},
delayedInitDotCOMplete: function()
{
if ((typeof(window.gURLBar) == "object") && window.gURLBar &&
window.handleURLBarCommand && (window.dotCOMplete.orighandleURLBarCommand == null))
{
// Replace original handleURLBarCommand, or TBP_handleURLBarCommand in case
// Tabbrowser Preferences extension v1.3.1.* (and up, hopefully) is installed
if (window.dotCOMplete.compatTBPrefs = (
window.TBP_handleURLBarCommand && (typeof(window.TBP_handleURLBarCommand) == 'function') &&
window.TBP_BrowserLoadURL && (typeof(window.TBP_BrowserLoadURL) == 'function')
))
{
window.dotCOMplete.realBrowserLoadURL = window.TBP_BrowserLoadURL;
window.dotCOMplete.orighandleURLBarCommand = window.TBP_handleURLBarCommand;
window.TBP_handleURLBarCommand = window.dotCOMplete.handleURLBarCommand;
}
else
{
window.dotCOMplete.realBrowserLoadURL = window.BrowserLoadURL;
window.dotCOMplete.orighandleURLBarCommand = window.handleURLBarCommand;
window.handleURLBarCommand = window.dotCOMplete.handleURLBarCommand;
}
Components.classes['@mozilla.org/consoleservice;1']
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage('dotCOMplete: Tabbrowser Preferences compatability mode: '+
(window.dotCOMplete.compatTBPrefs ? 'enabled' : 'disabled'));
// Cache list of active TLD's into an object for fast access
var oTLDs = {};
oTLDs.prototype = null;
for(var iCnt = window.dotCOMplete.TLDList.length; iCnt--;)
oTLDs[window.dotCOMplete.TLDList[iCnt]] = 0;
window.dotCOMplete._TLDList = oTLDs;
}
},
orighandleURLBarCommand: null,
handleURLBarCommand: function(aTriggeringEvent)
{
// This code is based on chrome://browser/content/browser.js and should provide identical functionality
// except for using dotCOMplete's version of canonizeUrl and the delayed loading in case a completion
// key combination was used. Based on the Firefox 1.6a version of handleURLBarCommand which is backwards
// compatible with the Firefox 1.0.
if (window.dotCOMplete._timer)
{
try { clearTimeout(window.dotCOMplete._timer); } catch(vErr) { /* ignore */ }
delete window.dotCOMplete._timer;
delete window.dotCOMplete._triggeringEvent;
delete window.dotCOMplete._URL;
}
var postData = { };
var iAction = window.dotCOMplete.canonizeUrl(aTriggeringEvent, postData);
if (window.dotCOMplete.compatTBPrefs && (aTriggeringEvent.type == "click") && (aTriggeringEvent.button == 0))
return; // This is what TBPrefs v1.3.1.1 does
switch(iAction) {
case 1: /* open immediately */
try { addToUrlbarHistory(gURLBar.value); } catch(vErr) { /* ignore */ }
window.dotCOMplete.realBrowserLoadURL(aTriggeringEvent,postData.value);
break;
case 2: /* open delayed */
window.dotCOMplete._URL = gURLBar.value;
window.dotCOMplete._triggeringEvent = {};
for(var sKey in aTriggeringEvent)
window.dotCOMplete._triggeringEvent[sKey] = aTriggeringEvent[sKey];
window.dotCOMplete._timer = setTimeout(window.dotCOMplete.BrowserLoadURL, window.dotCOMplete.preferences.getIntPref("loadDelay"));
}
},
canonizeUrl: function(aTriggeringEvent, aPostDataRef)
{
try
{
if (!(gURLBar && aTriggeringEvent))
throw "no completion requested";
// Fetch the optional completion information to apply
var iCompletion =
(('ctrlKey' in aTriggeringEvent) && ('shiftKey' in aTriggeringEvent) &&
(aTriggeringEvent.ctrlKey || aTriggeringEvent.shiftKey))
? (aTriggeringEvent.ctrlKey ? 1 : 0) + (aTriggeringEvent.shiftKey ? 2 : 0) - 1
: 3;
var oPrefs = window.dotCOMplete.preferences;
var sDefaultScheme = oPrefs.getCharPref(iCompletion+".scheme");
var bForceScheme = oPrefs.getBoolPref(iCompletion+".forceScheme");
var sPrefix = oPrefs.getCharPref(iCompletion+".FQNprefix");
var iMinParts = oPrefs.getIntPref(iCompletion+".FQNminparts");
var sTLDs = oPrefs.getCharPref(iCompletion+".FQNsuffixes");
// Test if completion is enabled, otherwise apply FF default loading mechanism
if ((sDefaultScheme == "") && (iMinParts <= 1) && (sTLDs == ""))
throw "no completion requested";
// Extract and correct the URL parts
var sURL = (new String(gURLBar.value)).replace(/^\s+/,"");
if (!/^\s*([^:]+:+\/*)?([^@\/]*@+)?((?:[^.\/:]*\.?)+)?(.*?)?\s*$/.test(sURL)) //*/
throw "unparseable URL"; // This should never be the case
var sScheme = RegExp.$1, sCredentials = RegExp.$2, sFQN = RegExp.$3, sPath = RegExp.$4;
sScheme = sScheme.replace(/\s+/g,"").replace(/:{2,}/g,":").replace(/\/{3,}$/,"//");
sFQN = sFQN.replace(/\s+/g,"").replace(/\.{2,}/g,".").replace(/^\.|\.$/,"").toLowerCase();
sPath = sPath.replace(/^\/{2,}/g,"/");
//if (!/[^.]{2,}/.test(sFQN))
// return 0; /* cancelled */
// Set the default scheme if not specified or different from forced scheme
var bIncorrectScheme = ((sDefaultScheme != "") && ((sScheme == "") || (bForceScheme && (sScheme != sDefaultScheme))));
if (bIncorrectScheme)
sScheme = sDefaultScheme;
// Find the current TLD and the one to cycle to
var iFQNLength = sFQN.length, sCurrentTLD = "", sNextTLD = "";
if (sTLDs != "")
{
var aTLD = sTLDs.toLowerCase().split(",");
aTLD.push(sNextTLD = aTLD[0]);
for(var sTLD; sTLD = aTLD.shift();)
if (sFQN.substr(iFQNLength - sTLD.length) == sTLD)
{
sFQN = sFQN.substr(0,iFQNLength - sTLD.length);
sCurrentTLD = sTLD;
sNextTLD = aTLD.shift();
break;
}
}
if (sCurrentTLD == "")
{
for(var sList, iCnt=3; iCnt--;)
if ((iCnt != iCompletion) && ((sList = oPrefs.getCharPref(iCnt+".FQNsuffixes").toLowerCase()) != ""))
for(var aTLD=sList.split(","), sTLD; sTLD = aTLD.shift();)
if (sFQN.substr(iFQNLength - sTLD.length) == sTLD)
{
sFQN = sFQN.substr(0,iFQNLength - sTLD.length);
sCurrentTLD = sTLD;
break;
}
if ((sCurrentTLD == "") && /\.([^.]+)$/.test(sFQN) &&
(RegExp.$1 in window.dotCOMplete._TLDList))
{
sFQN = sFQN.substr(0,iFQNLength - RegExp.$1.length - 1);
sCurrentTLD = "." + RegExp.$1;
}
}
// Precede the FQN with missing parts if less than the default minimum parts
var iNrFQNParts = (sFQN == "" ? 0 : sFQN.split(/\./).length) + 1 /* TLD is one already */
var bPartsAdded = false;
if (iNrFQNParts < iMinParts)
{
var aDefaultParts = sPrefix.split(/\./);
aDefaultParts.splice(iMinParts - iNrFQNParts);
var aPartsToInsert = [];
while(aDefaultParts.length && (sFQN+".").indexOf(aDefaultParts.join(".") + "."))
aPartsToInsert.push(aDefaultParts.shift());
if (aPartsToInsert.length)
{
iNrFQNParts += aPartsToInsert.length;
sFQN = aPartsToInsert.join(".") + "." + sFQN;
bPartsAdded = true;
}
}
// Complete the FQN with TLD
if (bIncorrectScheme || bPartsAdded) // Keep current TLD or select first TLD when other completions occurred
{
if (sCurrentTLD != "")
sFQN += sCurrentTLD;
else if (iNrFQNParts <= iMinParts)
sFQN += sNextTLD;
}
else if ((sCurrentTLD != "") || (sNextTLD != "")) // Otherwise cycle next TLD
sFQN += sNextTLD;
// Formulate completed URL
gURLBar.value = getShortcutOrURI(sScheme + sCredentials + sFQN + sPath, aPostDataRef);
return 2; /* open delayed */
}
catch(vErr)
{
window.canonizeUrl(aTriggeringEvent, aPostDataRef);
return 1; /* open immediately */
}
},
realBrowserLoadURL: null,
BrowserLoadURL: function()
{
window.dotCOMplete._timer = null;
if (window.dotCOMplete._URL == gURLBar.value)
{
try { addToUrlbarHistory(gURLBar.value); } catch(vErr) { /* ignore */ }
window.dotCOMplete.realBrowserLoadURL(window.dotCOMplete._triggeringEvent, null);
}
delete window.dotCOMplete._URL;
delete window.dotCOMplete._triggeringEvent;
},
initOptions: function(oDialog)
{
var oD = document, oPrefs = window.dotCOMplete.preferences;
oD.getElementById("loadDelay").value = oPrefs.getIntPref("loadDelay");
for(var iCnt=4; iCnt--;) {
oD.getElementById("scheme"+iCnt).value = oPrefs.getCharPref(iCnt+".scheme");
oD.getElementById("forceScheme"+iCnt).checked = oPrefs.getBoolPref(iCnt+".forceScheme");
oD.getElementById("FQNprefix"+iCnt).value = oPrefs.getCharPref(iCnt+".FQNprefix");
oD.getElementById("FQNminparts"+iCnt).value = oPrefs.getIntPref(iCnt+".FQNminparts");
oD.getElementById("FQNsuffixes"+iCnt).value = oPrefs.getCharPref(iCnt+".FQNsuffixes")
.replace(/^[.,]+/,"").replace(/,\.*/g,"\n");
}
oD.getElementById("hotKeys").selectedIndex = oD.getElementById("hotKeysDeck").selectedIndex;
},
applyOptions: function()
{
var oD = document, oPrefs = window.dotCOMplete.preferences;
oPrefs.setIntPref("loadDelay", parseInt("0"+oD.getElementById("loadDelay").value,10));
for(var iCnt=4; iCnt--;) {
var sScheme = oD.getElementById("scheme"+iCnt).value;
oPrefs.setCharPref(iCnt+".scheme", sScheme + ((sScheme!="" && sScheme.indexOf(":")==-1) ? ":" : ""));
oPrefs.setBoolPref(iCnt+".forceScheme", oD.getElementById("forceScheme"+iCnt).checked);
oPrefs.setCharPref(iCnt+".FQNprefix", oD.getElementById("FQNprefix"+iCnt).value);
oPrefs.setIntPref(iCnt+".FQNminparts", parseInt("0"+oD.getElementById("FQNminparts"+iCnt).value,10));
var sSuffixes = oD.getElementById("FQNsuffixes"+iCnt).value
.replace(/[ \t]+/g,"").replace(/\.{2,}/g,".")
.replace(/(?:\.*[\r\n,:\/@]\.*)+/g,",.").replace(/[,.]+$/,"");
oPrefs.setCharPref(iCnt+".FQNsuffixes", sSuffixes=="" ? "" : "."+sSuffixes);
}
}
};
window.addEventListener('load',dotCOMplete.initDotCOMplete,false);